define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {

            },
        },
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'score/score/index',
                    add_url: '',
                    edit_url: '',
                    // del_url: 'auth/adminlog/del',
                    // multi_url: 'auth/adminlog/multi',

                },
                showFooter:true
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        // {field: 'state', checkbox: true, },
                        // {field: 'id', title: 'ID', operate: false},
                        // {field: 'admin_id', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {
                            field: 'create_time', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true,
                            footerFormatter: function (value) {

                                return '合计';
                            }
                        },
                        // {field: 'user_id', title: '商户ID', formatter: Table.api.formatter.search},
                        {field: 'user.username', title: '商户账户', formatter: Table.api.formatter.search},
                        {field: 'consume', title: '消费积分',operate: false,footerFormatter: function (value) {
                                var count = 0;
                                for (var i in value) {
                                    count += parseFloat(value[i].consume);
                                }
                                return count;
                            }},
                        {field: 'topup', title: '充值积分',operate: false,footerFormatter: function (value) {
                                var count = 0;
                                for (var i in value) {
                                    count += parseFloat(value[i].topup);
                                }
                                return count;
                            }},
                        {field: 'deduct', title: '系统扣除积分', operate: false, formatter: Controller.api.formatter.browser,footerFormatter: function (value) {
                                var count = 0;
                                for (var i in value) {
                                    count += parseFloat(value[i].deduct);
                                }
                                return count;
                            }},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        }
    };
    return Controller;
});